//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.web.controller.member;

import com.aidong.dao.base.ConditionMap;
import com.aidong.dao.base.OrderSet;
import com.aidong.dao.base.Pagination;
import com.aidong.dao.wills.BoxRentDao;
import com.aidong.dao.wills.CardTypeCodeDao;
import com.aidong.dao.wills.CustomerComplaintDao;
import com.aidong.dao.wills.DicShopAreaCodeDao;
import com.aidong.dao.wills.MemberCardDao;
import com.aidong.dao.wills.MemberChangeCardDao;
import com.aidong.dao.wills.MemberContractDao;
import com.aidong.dao.wills.MemberEarnestDao;
import com.aidong.dao.wills.MemberInfoDao;
import com.aidong.dao.wills.MemberStopedCardDao;
import com.aidong.dao.wills.MemberUseDao;
import com.aidong.dao.wills.PssProductSaleListDao;
import com.aidong.dao.wills.PtBespeakDao;
import com.aidong.dao.wills.PtContractDao;
import com.aidong.model.wills.CardTypeCode;
import com.aidong.model.wills.MemberCard;
import com.aidong.model.wills.MemberContract;
import com.aidong.model.wills.MemberInfo;
import com.aidong.model.wills.PtContract;
import com.aidong.web.controller.BaseController;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping({"memberInfo"})
public class MemberInfoController extends BaseController {
    @Resource
    MemberInfoDao memberInfoDao;
    @Resource
    MemberContractDao memberContractDao;
    @Resource
    PtContractDao ptContractDao;
    @Resource
    MemberUseDao memberUseDao;
    @Resource
    MemberCardDao memberCardDao;
    @Resource
    CardTypeCodeDao cardTypeCodeDao;
    @Resource
    DicShopAreaCodeDao dicShopAreaCodeDao;
    @Resource
    PtBespeakDao ptBespeakDao;
    @Resource
    MemberStopedCardDao memberStopedCardDao;
    @Resource
    MemberChangeCardDao memberChangeCardDao;
    @Resource
    MemberEarnestDao memberEarnestDao;
    @Resource
    BoxRentDao boxRentDao;
    @Resource
    PssProductSaleListDao pssProductSaleListDao;
    @Resource
    CustomerComplaintDao customerComplaintDao;

    public MemberInfoController() {
    }

    @RequestMapping({"list"})
    public ModelAndView list() {
        return (new ModelAndView("member/info/list")).addObject("shopName", this.getTypeList("shopName"));
    }

    @RequestMapping({"_list"})
    public ModelAndView _list(@RequestParam(value = "shopCode",required = false) String shopCode, @RequestParam(value = "cardCode",required = false) String cardCode, @RequestParam(value = "memberCode",required = false) String memberCode, @RequestParam(value = "contractCode",required = false) String contractCode, @RequestParam(value = "kyogaCard",required = false) String kyogaCard, @RequestParam(value = "name",required = false) String name, @RequestParam(value = "pageNo",required = false) String pageNo, @RequestParam(value = "totalCount",required = false) String totalCount) {
        Pagination pg = new Pagination(1, 20);
        pg.setPage(this.parseInt(pageNo), this.parseInt(totalCount));
        if(!this.chkNull(cardCode) || !this.chkNull(memberCode) || !this.chkNull(name) || !this.chkNull(contractCode) || !this.chkNull(kyogaCard)) {
            ConditionMap mv = new ConditionMap();
            if(!this.chkNull(cardCode)) {
                MemberCard i$ = this.memberCardDao.getByCardCode(cardCode);
                if(i$ != null && !this.chkNull(i$.getMemberCode())) {
                    mv.eq("memberCode", i$.getMemberCode());
                } else {
                    ConditionMap member = new ConditionMap(1);
                    member.eq("cardCode", cardCode);
                    member.addSqlw("cardCode = ?+shopCode", new Object[]{cardCode});
                    mv.addSub(member);
                }
            }

            mv.eq("memberCode", memberCode);
            if(!this.chkNull(contractCode)) {
                List i$1 = this.memberContractDao.getMemberCodeByContractCode(contractCode);
                if(i$1 != null && i$1.size() > 0) {
                    mv.in("memberCode", i$1.toArray());
                } else {
                    mv.eq("memberCode", "null");
                }
            }

            mv.eq("kyogaCard", kyogaCard);
            if(!this.chkNull(name)) {
                ConditionMap i$2 = new ConditionMap(1);
                i$2.eq("chName", name);
                i$2.eq("enName", name);
                i$2.eq("idNumber", name);
                i$2.eq("mobile", name);
                mv.addSub(i$2);
            }

            this.memberInfoDao.queryPageList(pg, mv, (new OrderSet()).desc("createTime").asc("memberCode"));
            Iterator i$3 = pg.getResultList().iterator();

            while(i$3.hasNext()) {
                MemberInfo member1 = (MemberInfo)i$3.next();
                if(!this.isShopTypeCenter() && !member1.getShopCode().equalsIgnoreCase(this.getLoginShopCode())) {
                    member1.setStatus(Integer.valueOf(this.chkc(member1.getMemberCode())?1:0));
                } else {
                    member1.setStatus(Integer.valueOf(1));
                }

                if(!this.isShopTypeCenter() && !this.chkNull(member1.getIdNumber()) && member1.getIdNumber().length() >= 6) {
                    int n = member1.getIdNumber().length() / 2 - 1;
                    if(member1.getIdNumber().length() >= 18) {
                        n = 8;
                    }

                    int n0 = member1.getIdNumber().length() - n - 4;
                    if(n0 < 1) {
                        n0 = 1;
                    }

                    member1.setIdNumber(member1.getIdNumber().substring(0, n0) + "**********".substring(0, n) + member1.getIdNumber().substring(n0 + n));
                }
            }
        }

        ModelAndView mv1 = new ModelAndView("member/info/_list");
        mv1.addObject("list", pg.getResultList());
        mv1.addObject("pg", pg);
        return mv1;
    }

    private boolean chkc(String memberCode) {
        List list = this.memberContractDao.getCurrentListByMemberCode(memberCode);
        if(list != null && list.size() != 0) {
            String shopCode = this.getLoginShopCode();
            Iterator i$ = list.iterator();

            while(i$.hasNext()) {
                MemberContract contract = (MemberContract)i$.next();
                if(shopCode.equalsIgnoreCase(contract.getShopCode())) {
                    return true;
                }

                if(this.memberContractDao.chkContractShop(contract.getContractCode(), shopCode)) {
                    return true;
                }

                if(!this.chkNull(contract.getManyShop())) {
                    CardTypeCode cardType = (CardTypeCode)this.cardTypeCodeDao.getById(contract.getCardType());
                    if(cardType != null && cardType.getManyShopQuantity().intValue() == 0 && this.dicShopAreaCodeDao.chkAreaShop(contract.getManyShop(), shopCode)) {
                        return true;
                    }
                }
            }

            return false;
        } else {
            return false;
        }
    }

    @RequestMapping({"info"})
    public ModelAndView info(@RequestParam("memberCode") String memberCode) {
        MemberInfo member = this.memberInfoDao.getById(memberCode);
        if(member == null) {
            member = new MemberInfo();
        }

        MemberContract contract = this.memberContractDao.getByMemberCode(memberCode);
        if(!this.isShopTypeCenter() && !member.getShopCode().equalsIgnoreCase(this.getLoginShopCode())) {
            member.setStatus(Integer.valueOf(this.chkc(member.getMemberCode())?1:0));
        } else {
            member.setStatus(Integer.valueOf(1));
        }

        ModelAndView mv = new ModelAndView("member/info/info");
        mv.addObject("member", member);
        mv.addObject("contract", contract);
        mv.addObject("_picPath", this.getSetting("pic.path"));
        return mv;
    }

    @RequestMapping({"view"})
    public ModelAndView view(@RequestParam("memberCode") String memberCode) {
        MemberInfo member = this.memberInfoDao.getById(memberCode);
        if(member == null) {
            return this.showAlert("没有这个会员");
        } else {
            if(!this.isShopTypeCenter() && !member.getShopCode().equalsIgnoreCase(this.getLoginShopCode())) {
                member.setStatus(Integer.valueOf(this.chkc(member.getMemberCode())?1:0));
            } else {
                member.setStatus(Integer.valueOf(1));
            }

            ModelAndView mv = new ModelAndView("member/info/view");
            mv.addObject("member", member);
            return mv;
        }
    }

    @RequestMapping({"detail"})
    public ModelAndView detail(@RequestParam("memberCode") String memberCode) {
        MemberInfo member = this.memberInfoDao.getById(memberCode);
        if(member == null) {
            member = new MemberInfo();
        }

        if(!this.isShopTypeCenter()) {
            if(!this.chkNull(member.getIdNumber()) && member.getIdNumber().length() >= 6) {
                int mv = member.getIdNumber().length() / 2 - 1;
                if(member.getIdNumber().length() >= 18) {
                    mv = 8;
                }

                int n0 = member.getIdNumber().length() - mv - 4;
                if(n0 < 1) {
                    n0 = 1;
                }

                member.setIdNumber(member.getIdNumber().substring(0, n0) + "**********".substring(0, mv) + member.getIdNumber().substring(n0 + mv));
            }

            member.setIdCardPhoto((String)null);
        }

        ModelAndView mv1 = new ModelAndView("member/info/detail");
        mv1.addObject("member", member);
        mv1.addObject("_picPath", this.getSetting("pic.path"));
        return mv1;
    }

    @RequestMapping({"contract"})
    public ModelAndView contract(@RequestParam("memberCode") String memberCode) {
        List list = this.memberContractDao.getListByMemberCode(memberCode);
        Iterator mv = list.iterator();

        while(mv.hasNext()) {
            MemberContract contract = (MemberContract)mv.next();
            Double leftAmount = null;
            Date beginTime = contract.getBeginTime();
            Date endTime = contract.getEndTime();
            if(beginTime != null && endTime != null && contract.getStatus().intValue() == 1 && contract.getEffectiveDate() == null && !"8".equals(contract.getSaleType())) {
                if(endTime.getTime() < System.currentTimeMillis()) {
                    leftAmount = Double.valueOf(0.0D);
                } else if(contract.getTotalCount().intValue() > 0) {
                    leftAmount = Double.valueOf((double)Math.round((double)contract.getRestCount().intValue() * contract.getFactPrice().doubleValue() / (double)contract.getTotalCount().intValue()));
                } else if(beginTime.getTime() > System.currentTimeMillis()) {
                    leftAmount = contract.getFactPrice();
                } else {
                    leftAmount = Double.valueOf((double)Math.round((double)(endTime.getTime() - System.currentTimeMillis()) * contract.getFactPrice().doubleValue() / (double)(endTime.getTime() - beginTime.getTime())));
                }

                if(leftAmount.doubleValue() > contract.getFactPrice().doubleValue()) {
                    leftAmount = contract.getFactPrice();
                }

                if(leftAmount.doubleValue() <= 0.0D) {
                    leftAmount = Double.valueOf(0.0D);
                }
            }

            contract.setOutAmount(leftAmount);
            if(contract.getNewEndTime() != null) {
                endTime = contract.getNewEndTime();
            }

            if(endTime != null && endTime.getTime() < System.currentTimeMillis()) {
                contract.setStatus(Integer.valueOf(3));
            }
        }

        ModelAndView mv1 = new ModelAndView("member/info/contract");
        mv1.addObject("list", list);
        return mv1;
    }

    @RequestMapping({"ptcontract"})
    public ModelAndView ptcontract(@RequestParam("memberCode") String memberCode) {
        List list = this.ptContractDao.getListByMemberCode(memberCode);
        Iterator mv = list.iterator();

        while(mv.hasNext()) {
            PtContract contract = (PtContract)mv.next();
            if(contract.getEndTime().getTime() < System.currentTimeMillis()) {
                contract.setStatus(Integer.valueOf(3));
            }
        }

        ModelAndView mv1 = new ModelAndView("member/info/ptcontract");
        mv1.addObject("list", list);
        return mv1;
    }

    @RequestMapping({"earnest"})
    public ModelAndView earnest(@RequestParam("memberCode") String memberCode) {
        List list = this.memberEarnestDao.getListByMemberCode(memberCode);
        ModelAndView mv = new ModelAndView("member/info/earnest");
        mv.addObject("list", list);
        return mv;
    }

    @RequestMapping({"boxrent"})
    public ModelAndView boxrent(@RequestParam("memberCode") String memberCode) {
        List list = this.boxRentDao.getListByMemberCode(memberCode);
        ModelAndView mv = new ModelAndView("member/info/boxrent");
        mv.addObject("list", list);
        return mv;
    }

    @RequestMapping({"prodsale"})
    public ModelAndView prodsale(@RequestParam("memberCode") String memberCode, @RequestParam(value = "pageNo",required = false) String pageNo, @RequestParam(value = "totalCount",required = false) String totalCount) {
        Pagination pg = new Pagination(1, 20);
        pg.setPage(this.parseInt(pageNo), this.parseInt(totalCount));
        ConditionMap cd = new ConditionMap();
        cd.eq("memberCode", memberCode);
        this.pssProductSaleListDao.getLstSale(pg, cd);
        ModelAndView mv = new ModelAndView("member/info/prodsale");
        mv.addObject("list", pg.getResultList());
        mv.addObject("pg", pg);
        return mv;
    }

    @RequestMapping({"mbuse"})
    public ModelAndView mbuse(@RequestParam("memberCode") String memberCode, @RequestParam(value = "pageNo",required = false) String pageNo, @RequestParam(value = "totalCount",required = false) String totalCount) {
        Pagination pg = new Pagination(1, 20);
        pg.setPage(this.parseInt(pageNo), this.parseInt(totalCount));
        ConditionMap cd = new ConditionMap();
        cd.eq("memberCode", memberCode);
        this.memberUseDao.queryPageList(pg, cd, (new OrderSet()).desc("inTime"));
        ModelAndView mv = new ModelAndView("member/info/mbuse");
        mv.addObject("list", pg.getResultList());
        mv.addObject("pg", pg);
        return mv;
    }

    @RequestMapping({"ptbespeak"})
    public ModelAndView ptbespeak(@RequestParam("memberCode") String memberCode, @RequestParam(value = "pageNo",required = false) String pageNo, @RequestParam(value = "totalCount",required = false) String totalCount) {
        Pagination pg = new Pagination(1, 20);
        pg.setPage(this.parseInt(pageNo), this.parseInt(totalCount));
        ConditionMap cd = new ConditionMap();
        cd.eq("memberCode", memberCode);
        cd.gt("status", Integer.valueOf(0));
        this.ptBespeakDao.queryPageList(pg, cd, (new OrderSet()).desc("classTime"));
        ModelAndView mv = new ModelAndView("member/info/ptbespeak");
        mv.addObject("list", pg.getResultList());
        mv.addObject("pg", pg);
        return mv;
    }

    @RequestMapping({"stopcard"})
    public ModelAndView stopcard(@RequestParam("memberCode") String memberCode) {
        List list = this.memberStopedCardDao.getListByMemberCode(memberCode);
        ModelAndView mv = new ModelAndView("member/info/stopcard");
        mv.addObject("list", list);
        return mv;
    }

    @RequestMapping({"chgcard"})
    public ModelAndView chgcard(@RequestParam("memberCode") String memberCode) {
        List list = this.memberChangeCardDao.getListByMemberCode(memberCode);
        ModelAndView mv = new ModelAndView("member/info/chgcard");
        mv.addObject("list", list);
        return mv;
    }

    @RequestMapping({"complaint"})
    public ModelAndView complaint(@RequestParam("memberCode") String memberCode) {
        List list = this.customerComplaintDao.getListByMemberCode(memberCode);
        ModelAndView mv = new ModelAndView("member/info/complaint");
        mv.addObject("list", list);
        return mv;
    }
}
